'use strict'

function Student(props){
    this.name=props.name || '匿名';
    this.grade=props.grade || 1;
}

Student.prototype.hello=function(){
    console.log('Hello,' +this.name + '!');
};

function createStudent(props){
    return new Student(props || {})
}

var xiaoming=createStudent({
    name:'小明'
});

console.log(xiaoming.grade);

//-------------------------------------------------------------

//  练习题

 class Animal{
     constructor(name){
         this.name=name;
     }
 }

 class Cat extends Animal{
     constructor(name){
         super(name);
     }
     say(){
         return `Hello, ${this.name}!`;
     }
 }



// 测试:
var kitty = new Cat('Kitty');
var doraemon = new Cat('哆啦A梦');
if (kitty && kitty.name === 'Kitty'
    && kitty.say
    && typeof kitty.say === 'function'
    && kitty.say() === 'Hello, Kitty!'
    && kitty.say === doraemon.say
) {
    console.log('测试通过!');
} else {
    console.log('测试失败!');
}

// 原型继承

function Studnet(props){
    this.name=props.name || 'Unnamed';
}

Student.prototype.hello=function(){
    console.log('Hello,' + this.name +'!');
}

function PrimaryStudnent(props){
    Student.call(this.props);
    this.grade=props.grade || 1;
}

// 原型继承

function Human(){
    this.name="teacher";
    this.age=39;
}

function Man(){
    Man.prototype =new Human();
    var m=new Man();
   //此时Man.name=teacher;Man.age=39;
   
}

Man();

// class 继承

class Student{
    constructor(name){
        this.name=name;
    }
    hello(){
        console.log('Hello,' + this.name + '!');
    }
}
